home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume1 / rot2 < prev    next >
Encoding:
Text File  |  1987-04-22  |  12.6 KB  |  553 lines

  1. Path: seismo!rutgers!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games-request
  2. From: games-request@tekred.TEK.COM
  3. Newsgroups: mod.sources.games
  4. Subject: v01i005:  rot2 - waterfall terminal display, version 2
  5. Message-ID: <1105@tekred.TEK.COM>
  6. Date: 21 Apr 87 20:57:57 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 542
  9. Approved: billr@tekred.TEK.COM
  10.  
  11. Submitted by: Bill Randle <games-request@tekred.TEK.COM>
  12. Mod.sources.games: Volume 1, Issue 5
  13. Archive-name: rot2
  14.  
  15.     [Thanks to those of you who sent in bug fixes for the original
  16.      rot program.  This issue has the new improved version.  The
  17.      source is short enough that I decided to repost the whole
  18.      thing rather than just a patch, so delete the original one
  19.      (v01i002, Archive-name: rot).]
  20.                  ----------
  21.     [You are not missing v01i004.  That issue was originally a
  22.      patch to rot that was subsequently canceled after more patches
  23.      came in.   -br]
  24.  
  25. #! /bin/sh
  26. # This is a shell archive.  Remove anything before this line, then unpack
  27. # it by saving it into a file and typing "sh file".  To overwrite existing
  28. # files, type "sh file -c".  You can also feed this as standard input via
  29. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  30. # will see the following message at the end:
  31. #        "End of shell archive."
  32. # Contents:  Makefile README patchlvl.h rot.c
  33. # Wrapped by billr@tekred on Tue Apr 21 13:44:09 1987
  34. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  35. if test -f Makefile -a "${1}" != "-c" ; then 
  36.   echo shar: Will not over-write existing file \"Makefile\"
  37. else
  38. echo shar: Extracting \"Makefile\" \(129 characters\)
  39. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  40. X# Simple makefile for rot program
  41. X
  42. XCFLAGS = -O #-DSYSV
  43. X
  44. Xrot:    rot.c
  45. X    cc $(CFLAGS) -o rot rot.c -ltermlib
  46. X
  47. Xtest:    rot
  48. X    ./rot <rot.c
  49. END_OF_Makefile
  50. if test 129 -ne `wc -c <Makefile`; then
  51.     echo shar: \"Makefile\" unpacked with wrong size!
  52. fi
  53. # end of overwriting check
  54. fi
  55. if test -f README -a "${1}" != "-c" ; then 
  56.   echo shar: Will not over-write existing file \"README\"
  57. else
  58. echo shar: Extracting \"README\" \(648 characters\)
  59. sed "s/^X//" >README <<'END_OF_README'
  60. XThis program cascades letters from the top of the terminal screen
  61. Xto the bottom in a waterfall effect.  The original program has had
  62. Xa few bugs fixed and added capability to properly handle padding.
  63. XAlso, this will be pretty slow at lower baudrates.
  64. X
  65. X                        4/21/87 BR
  66. X
  67. X--
  68. XOriginal source from:
  69. X    Peter da Silva (ihnp4!shell!neuro1!{hyd-ptd,datafact,baylor}!peter)
  70. X
  71. XMakefile and README from:
  72. X    Bill Randle (billr@tekred.TEK.COM)
  73. X
  74. XBug fixes from:
  75. X    James Buster (bitbug@ucscb.ucsc.edu)
  76. X    Ed Falk (ed@sun -?)
  77. X    Andrew Klossner (andrew@lemming.gwd.tek.com)
  78. X    Andrew Scott Beals (bandy@amdcad.amd.com)
  79. X    Bill Randle (billr@tekred.tek.com)
  80. END_OF_README
  81. if test 648 -ne `wc -c <README`; then
  82.     echo shar: \"README\" unpacked with wrong size!
  83. fi
  84. # end of overwriting check
  85. fi
  86. if test -f patchlvl.h -a "${1}" != "-c" ; then 
  87.   echo shar: Will not over-write existing file \"patchlvl.h\"
  88. else
  89. echo shar: Extracting \"patchlvl.h\" \(76 characters\)
  90. sed "s/^X//" >patchlvl.h <<'END_OF_patchlvl.h'
  91. X#define    PATCHLEVEL    0
  92. X
  93. X#define ROT_VERSION    "2.0 patchlevel 0, 21 April 1987"
  94. END_OF_patchlvl.h
  95. if test 76 -ne `wc -c <patchlvl.h`; then
  96.     echo shar: \"patchlvl.h\" unpacked with wrong size!
  97. fi
  98. # end of overwriting check
  99. fi
  100. if test -f rot.c -a "${1}" != "-c" ; then 
  101.   echo shar: Will not over-write existing file \"rot.c\"
  102. else
  103. echo shar: Extracting \"rot.c\" \(8725 characters\)
  104. sed "s/^X//" >rot.c <<'END_OF_rot.c'
  105. X/*
  106. X * Revision History:
  107. X *
  108. X * Original source from:
  109. X *  Peter da Silva (ihnp4!shell!neuro1!{hyd-ptd,datafact,baylor}!peter)
  110. X *
  111. X * Changes for padding added by:
  112. X *  Andrew Scott Beals ({ucbvax,decwrl}!amdcad!bandy or bandy@amdcad.amd.com)
  113. X *  20 April 1987
  114. X *
  115. X * Additional changes for padding, fix for computation of tglen,
  116. X * increase max lines, improve termlib handling, add System V #ifdefs.
  117. X *  Bill Randle (billr@tekred.TEK.COM)
  118. X *  21 April 1987
  119. X */
  120. X
  121. X#include <stdio.h>
  122. X#include "patchlvl.h"
  123. X
  124. X#ifdef SYSV
  125. X# include <termio.h>
  126. X#else
  127. X# include <sgtty.h>
  128. X#endif
  129. X
  130. X/*        -- Miscellaneous defines --                     */
  131. X#define FALSE 0
  132. X#define TRUE 1
  133. X#define MAXCOL 80
  134. X#define MAXLI 34
  135. X
  136. Xextern char *tgetstr();
  137. X
  138. Xint lastx, lasty;
  139. Xstruct _c {
  140. X    struct _c *c_next;
  141. X    int c_line, c_column;
  142. X    char c_mark;
  143. X} *clist;
  144. X
  145. X/*        -- Global variables --                         */
  146. Xchar *tent;                                               /* Pointer to tbuf */
  147. Xextern char PC;                                             /* Pad character */
  148. Xextern char *UP, *BC;                         /* Upline, backsapce character */
  149. Xextern short ospeed;                                /* Terminal output speed */
  150. Xint tglen;
  151. X
  152. Xchar *cm,                                                   /* Cursor motion */
  153. X     *cl,                                                    /* Clear screen */
  154. X     *ti,                            /* Init terminal */
  155. X     *te;                           /* Reset terminal */
  156. Xint  li,                                                  /* lines on screen */
  157. X     co;                                                    /* columns ditto */
  158. Xchar screen[MAXLI+1][MAXCOL];
  159. Xchar newscreen[MAXLI+1][MAXCOL];
  160. X
  161. Xmain(ac, av)
  162. Xint ac;
  163. Xchar **av;
  164. X{
  165. X    /* set ospeed so padding works correctly */
  166. X#ifdef SYSV
  167. X    struct termio    p;
  168. X
  169. X    if(ioctl(1, TCGETA, &p) != -1)
  170. X        ospeed=p.c_cflag & CBAUD;
  171. X#else
  172. X    struct sgttyb    p;
  173. X
  174. X    if(ioctl(1, TIOCGETP, &p) != -1)
  175. X        ospeed=p.sg_ospeed;
  176. X#endif
  177. X
  178. X    srand(getpid());
  179. X    tinit(getenv("TERM"));
  180. X    if(av[1])
  181. X        while(*++av)
  182. X            dropf(*av);
  183. X    else
  184. X        fdropf(stdin);
  185. X    tend();
  186. X}
  187. X
  188. Xat(x, y, c)
  189. Xint x, y;
  190. Xchar c;
  191. X{
  192. X#ifdef DEBUG
  193. X    _at(x, y);
  194. X#else
  195. X    if(y==lasty) {
  196. X        if(x!=lastx) {
  197. X            if(x<lastx && lastx-x<tglen)
  198. X                while(x<lastx) {
  199. X                    putchar('\b');
  200. X                    lastx--;
  201. X                }
  202. X            else if(x>lastx && x-lastx<tglen)
  203. X                while(x>lastx) {
  204. X                    putchar(newscreen[lasty][lastx]);
  205. X                    lastx++;
  206. X                }
  207. X            else
  208. X                _at(x, y);
  209. X        }
  210. X    } else
  211. X        _at(x, y);
  212. X#endif
  213. X    c &= ~0200;
  214. X    putchar(c);
  215. X    if(c >= ' ' && c != '\177')
  216. X        lastx++;
  217. X    if(lastx>=co) {
  218. X        lastx -= co;
  219. X        lasty++;
  220. X    }
  221. X}
  222. X
  223. X_at(x, y)
  224. Xint x, y;
  225. X{
  226. X    extern void    outc();
  227. X
  228. X    tputs(tgoto(cm, x, y), 1, outc);     /* handle padding */
  229. X    lastx = x;
  230. X    lasty = y;
  231. X}
  232. X
  233. Xvoid
  234. Xoutc(c)
  235. Xregister c;
  236. X{
  237. X    putc(c, stdout);
  238. X}
  239. X
  240. Xtinit(name)
  241. Xchar *name;
  242. X{
  243. X    static char junkbuf[1024], *junkptr;
  244. X    char tbuf[1024];
  245. X    int  intr();
  246. X
  247. X    junkptr = junkbuf;
  248. X
  249. X    tgetent(tbuf, name);
  250. X
  251. X    if (!tgetflag("bs"))        /* is backspace not used? */
  252. X        BC = tgetstr("bc",&junkptr);    /* find out what is */
  253. X    else
  254. X        BC = "\b";        /* make a backspace handy */
  255. X    if (tgetstr("pc", &junkptr) != NULL)
  256. X        PC = *junkptr;  /* set pad character */
  257. X    else
  258. X        PC = '\0';
  259. X    UP = tgetstr("up", &junkptr);
  260. X    cm = tgetstr("cm", &junkptr);
  261. X    if (cm == NULL) {
  262. X        printf("Can't rot on dumb terminals.\n");
  263. X        exit(1);
  264. X    }
  265. X    cl = tgetstr("cl", &junkptr);
  266. X    ti = tgetstr("ti", &junkptr);
  267. X    te = tgetstr("te", &junkptr);
  268. X    li = min(tgetnum("li"), MAXLI);
  269. X    if (li == -1)
  270. X        li = 24;
  271. X    co = min(tgetnum("co"), MAXCOL);
  272. X    if (co == -1)
  273. X        co = 80;
  274. X    tglen = strlen(tgoto(cm, co-1, li-1));
  275. X}
  276. X
  277. Xtend()
  278. X{
  279. X    outs(te);
  280. X    _at(0, li-1);
  281. X    putchar('\n');
  282. X    fflush(stdout);
  283. X}
  284. X
  285. Xreadscreen(fp)
  286. XFILE *fp;
  287. X{
  288. X    int line, column, p;
  289. X    char tmp[256];
  290. X
  291. X    for(line=0; line<li; line++)
  292. X        for(column=0; column<co; column++)
  293. X            newscreen[line][column] = screen[line][column] = ' ';
  294. X    for(column=0; column<co; column++)
  295. X        newscreen[li][column] = screen[li][column] = '*';
  296. X    line=0;
  297. X    while(line<li) {
  298. X        if(!fgets(tmp, 256, fp))
  299. X            return;
  300. X
  301. X        for(column=0, p=0; tmp[p]; p++) {
  302. X            tmp[p] &= ~0200;
  303. X            if(tmp[p] < ' ' || tmp[p] == 127)
  304. X                switch(tmp[p]) {
  305. X                    case '\t':
  306. X                        while(++column % 8)
  307. X                            continue;
  308. X                        break;
  309. X                    case '\n':
  310. X                        column = 0;
  311. X                        line++;
  312. X                        break;
  313. X                    default:
  314. X                        newscreen[line][column] = '^';
  315. X                        column++;
  316. X                        if(column>=co) {
  317. X                            column -= co;
  318. X                            line++;
  319. X                        }
  320. X                        newscreen[line][column] =
  321. X                            (tmp[p]+'@') & 127;
  322. X                        column++;
  323. X                        break;
  324. X                }
  325. X            else {
  326. X                newscreen[line][column] = tmp[p];
  327. X                column++;
  328. X            }
  329. X            if(column >= co) {
  330. X                column -= co;
  331. X                line++;
  332. X            }
  333. X            if(line >= li)
  334. X                break;
  335. X        }
  336. X    }
  337. X    for(column=0; column<co; column++)
  338. X        newscreen[line][column] = screen[li][column] = '*';
  339. X}
  340. X
  341. Xdrawscreen()
  342. X{
  343. X    lastx = lasty = 0;
  344. X    outs(cl);
  345. X    update();
  346. X}
  347. X
  348. Xupdate() /* copy new screen back to old screen */
  349. X{
  350. X    int l, c;
  351. X
  352. X    for(l=0; l<li; l++)
  353. X        for(c=0; c<co; c++)
  354. X            if(screen[l][c] != newscreen[l][c]) {
  355. X                if((screen[l][c] & ~0200) !=
  356. X                   (newscreen[l][c] & ~0200))
  357. X                    at(c, l, newscreen[l][c]);
  358. X                screen[l][c] = newscreen[l][c];
  359. X            }
  360. X}
  361. X
  362. Xdrop(line, column)
  363. Xint line, column;
  364. X{
  365. X    struct _c *hold;
  366. X
  367. X    if(line<0 || line>=li || column<0 || column>=co ||
  368. X       (line>=li-2 && column >= co-1) || /* scroll potential */
  369. X       screen[line][column]==' ' || /* empty */
  370. X       screen[line][column] & 0200) /* already in list */
  371. X        return;
  372. X    if(screen[line+1][column]!=' ' &&
  373. X       (column==co-1 ||screen[line+1][column+1]!=' ') &&
  374. X       (column==0 ||screen[line+1][column-1]!=' '))
  375. X        return;
  376. X
  377. X    hold = (struct _c *) malloc(sizeof(struct _c));
  378. X    hold -> c_next = clist;
  379. X    hold -> c_column = column;
  380. X    hold -> c_line = line;
  381. X    hold -> c_mark = 0;
  382. X    screen[line][column] |= 0200;
  383. X    clist = hold;
  384. X}
  385. X
  386. Xdrops()
  387. X{
  388. X    int l, c;
  389. X    struct _c *hold;
  390. X    for(hold = clist; hold; hold=hold->c_next) {
  391. X        int line = hold->c_line, column=hold->c_column;
  392. X        if(line>= li-2 && column>=co-1) {
  393. X            newscreen[line][column] &= ~0200;
  394. X            screen[line][column] &= ~0200;
  395. X            hold->c_mark = 1;
  396. X            continue;
  397. X        }
  398. X        drop(line+1, column);
  399. X        drop(line, column+1);
  400. X        drop(line-1, column);
  401. X        drop(line, column-1);
  402. X        if(newscreen[line+1][column]==' ') {
  403. X            newscreen[line+1][column] = screen[line][column];
  404. X            newscreen[line][column] = ' ';
  405. X            line++;
  406. X        } else if(rand()&01000) {
  407. X            if(column>0 && newscreen[line][column-1] == ' ' &&
  408. X                newscreen[line+1][column-1]==' ') {
  409. X                newscreen[line][column-1] =
  410. X                    screen[line][column];
  411. X                newscreen[line][column] = ' ';
  412. X                column--;
  413. X            }
  414. X            else if(column<co-1 &&
  415. X                newscreen[line][column+1] == ' ' &&
  416. X                newscreen[line+1][column+1]==' ') {
  417. X                    newscreen[line][column+1] =
  418. X                        screen[line][column];
  419. X                    newscreen[line][column] = ' ';
  420. X                    column++;
  421. X            }
  422. X            else {
  423. X                screen[line][column] &= ~0200;
  424. X                newscreen[line][column] &= ~0200;
  425. X                hold -> c_mark = 1;
  426. X            }
  427. X        } else {
  428. X            if(column<co-1 && newscreen[line][column+1] == ' ' &&
  429. X                newscreen[line+1][column+1]==' ') {
  430. X                newscreen[line][column+1] =
  431. X                    screen[line][column];
  432. X                newscreen[line][column] = ' ';
  433. X                column++;
  434. X            }
  435. X            else if(column>0 && newscreen[line][column-1] == ' ' &&
  436. X                newscreen[line+1][column-1]==' ') {
  437. X                newscreen[line][column-1] =
  438. X                    screen[line][column];
  439. X                newscreen[line][column] = ' ';
  440. X                column--;
  441. X            }
  442. X            else {
  443. X                newscreen[line][column] &= ~0200;
  444. X                screen[line][column] &= ~0200;
  445. X                hold -> c_mark = 1;
  446. X            }
  447. X        }
  448. X        hold -> c_column = column;
  449. X        hold -> c_line = line;
  450. X        fflush(stdout);
  451. X    }
  452. X
  453. X    while(clist && clist->c_mark) {
  454. X        struct _c *p = clist;
  455. X        clist = clist -> c_next;
  456. X        free(p);
  457. X    }
  458. X    hold = clist;
  459. X    while(hold && hold->c_next)
  460. X        if(hold->c_next->c_mark) {
  461. X            struct _c *p = hold->c_next;
  462. X            hold->c_next = p->c_next;
  463. X            free(p);
  464. X        } else
  465. X            hold=hold->c_next;
  466. X}
  467. X
  468. Xdroplet(line, column)
  469. Xint line, column;
  470. X{
  471. X    int ret;
  472. X    while(column>=0 && screen[line][column]!=' ')
  473. X        column--;
  474. X    column++;
  475. X    while(column<co && screen[line][column]!=' ')
  476. X        drop(line, column++);
  477. X    ret = clist != 0;
  478. X    while(clist) {
  479. X        drops();
  480. X        update();
  481. X    }
  482. X    return ret;
  483. X}
  484. X
  485. Xdropscreen()
  486. X{
  487. X    int column, line;
  488. X    int rubbish = 0, count = 0;
  489. X
  490. X    do {
  491. X        int start, limit, incr;
  492. X        count++;
  493. X        rubbish = 0;
  494. X        if(count&1) { start=li-2; limit=0; incr = -1; }
  495. X        else { start=0; limit=li-2; incr=1; }
  496. X        for(line=start; line!=limit && !rubbish; line+=incr) {
  497. X            if(line&1)
  498. X                for(column=0; column<co && !rubbish; column++)
  499. X                    rubbish += droplet(line, column);
  500. X            else
  501. X                for(column=co-1; column>=0 && !rubbish; column--)
  502. X                    rubbish += droplet(line, column);
  503. X        }
  504. X    } while(rubbish);
  505. X}
  506. X
  507. Xdropf(file)
  508. Xchar *file;
  509. X{
  510. X    FILE *fp;
  511. X
  512. X    if(!(fp = fopen(file, "r"))) {
  513. X        perror(file);
  514. X        return -1;
  515. X    }
  516. X    fdropf(fp);
  517. X}
  518. X
  519. Xfdropf(fp)
  520. XFILE *fp;
  521. X{
  522. X    int i;
  523. X
  524. X    while(!feof(fp)) {
  525. X        readscreen(fp);
  526. X        drawscreen();
  527. X        for(i=0; i<20; i++)
  528. X            droplet((rand()>>4) % li, (rand()>>4) % co);
  529. X        dropscreen();
  530. X    }
  531. X}
  532. X
  533. Xouts(s)
  534. Xchar *s;
  535. X{
  536. X    fputs(s, stdout);
  537. X}
  538. X
  539. Xmin(a, b)
  540. Xint a, b;
  541. X{
  542. X    if(a<b) return a;
  543. X    return b;
  544. X}
  545. END_OF_rot.c
  546. if test 8725 -ne `wc -c <rot.c`; then
  547.     echo shar: \"rot.c\" unpacked with wrong size!
  548. fi
  549. # end of overwriting check
  550. fi
  551. echo shar: End of shell archive.
  552. exit 0
  553.